﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using SpiritAlight.Input;
using SpiritAlight.GeneralClac;

namespace SpiritAlight.Stage
{
    static class Camera
    {
        static Vector2 position;

        static Vector2 moveVector;
        static Vector2 lossSpeed;

        /// <summary>
        /// マウス動作で座標を動かす
        /// </summary>
        /// <param name="input"></param>
        public static void Update()
        {
            
            if (InputState.IsDown(MouseButton.Left))
            {
                position -= InputState.MoveDistance;
            }
            if (InputState.IsMouseButton(MouseButton.Left) == DeviceState.Released)
            {
                moveVector = InputState.MoveDistance;
                lossSpeed = moveVector / 20;
            }

            if (moveVector != Vector2.Zero)
            {
                position -= moveVector;
                moveVector -= lossSpeed;
                if (Calc.IsApproximation(moveVector, Vector2.Zero, new Vector2(1.0f, 1.0f)))
                    moveVector = Vector2.Zero;
            }

            if (position.X < 0.0f)
                position.X = 0.0f;
            if (position.Y < 0.0f)
                position.Y = 0.0f;

            if (position.X > Coordinate.WorldSize.X - Coordinate.ScreenSize.X)
                position.X = Coordinate.WorldSize.X - Coordinate.ScreenSize.X;
            if (position.Y > Coordinate.WorldSize.Y - Coordinate.ScreenSize.Y)
                position.Y = Coordinate.WorldSize.Y - Coordinate.ScreenSize.Y;
        }

        public static Vector2 Position 
        {
            get { return position; }
            set { position = value; }
        }
    }
}
